var e = ["blur", "focus", "contextmenu", "load", "resize", "scroll", "unload",
    "click", "dblclick", "mousedown", "mouseup", "mouseenter", "mouseleave",
    "mousemove", "mouseover", "mouseout", "change", "reset", "select", "submit",
    "keydown", "keypress", "keyup", "abort", "error", "ready"];
for (var i = 0; i < e.length; i++) {
    (function () {
        var o = e[i];
        $.fn[o] = function (f) { return this.bind(o, f); };
    })();
}

$.fn.ready = function(f) {
    return this.each(function () {
        if (this.$$timer) { // 创建了延迟执行的队列
            this.$$ready.push(f);
        } else {
            var obj = this;
            this.$$ready = [f];
            this.$$timer = setInterval(function () { // 移除之前每13ms执行一次
                // 确保页面加载完毕     
                if (obj && obj.getElementsByTagName && obj.getElementById && obj.body) { 
                    clearInterval(obj.$$timer);
                    obj.$$timer = null;
                    for (var i = 0; i < obj.$$ready.length; i++) {
                        $.apply(obj, obj.$$ready[i]);
                    }
                    obj.$$ready = null;
                }            
            }, 13);
        }
    });
};

// Deprecated
$.fn.onready = $.fn.ready;